package org.example.springbook.controller;


import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session){
        System.out.println("接收到的参数:" + name);
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            System.out.println(false);
            return false;
        }
        if("admin".equals(name) && "admin".equals(password)){
            session.setAttribute("username",name);
            System.out.println(true);
            return true;
        }
        System.out.println(false);
        return false;
    }
}
